<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${_cxt}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/htcomlistcs.css" />
		<script type="text/javascript" src="js/jquery-2.2.3.min.js"></script>
		<script type="text/javascript">
			var i=0;
			$(function(){
				$(".selecttiaojian").click(function(){
					$(".dropdown1").toggle();
				})
				$(".piliang").click(function(){
					$(".dropdown2").toggle();
				})
				//全选按钮脚本
				$("#selectall").click(function(){
					if(i%2==0){
						$(".list-table").find("input[type=checkbox]").prop('checked', true);
					}else{
						console.log("fdfdf");
						$(".list-table").find("input[type=checkbox]").prop('checked',false);
					}
					i++;
					
				})
				//批量上架
				$("#upall").click(function(){
					$(".list-table input[type=checkbox]").each(function(i,v){
						if(v.checked){
							$(v).parents("tr").find(".selectisup").val("up");
							var cid=$(v).attr("cid");
							console.log(v);
							$.ajax({
								type:"post",
								url:"htmain?v=ajaxUp",
								data:"cid="+cid+"&isup=0",
								success:function(msg){
									
								}
							})
							
						}
					})
				})
				//批量下架
				$("#downall").click(function(){
					$(".list-table input[type=checkbox]").each(function(i,v){
						if(v.checked){
							$(v).parents("tr").find(".selectisup").val("down");
							var cid=$(v).attr("cid");
							$.ajax({
								type:"post",
								url:"htmain?v=ajaxUp",
								data:"cid="+cid+"&isup=1",
								success:function(msg){
									
								}
							})
						}
					})
				})
				//上下架
				$(".selectisup").change(function(){
					
					var str=$(this).val();
					var cid=$(this).attr("cid")
					console.log(cid,str);
					if(str=="up"){
						$.ajax({
							type:"post",
							url:"htmain?v=ajaxUp",
							data:"cid="+cid+"&isup=0",
							success:function(msg){
								
							}
						})
					}else{
						$.ajax({
							type:"post",
							url:"htmain?v=ajaxUp",
							data:"cid="+cid+"&isup=1",
							success:function(msg){
								
							}
						})
					}
				})
				
			})
		</script>
	</head>
	<body>
		<div class="lg-side">
			<div class="inbox-head">
				<h3>商品列表</h3>
				<form class="pull-right position" method="post" action="htmain?v=likeName">
					<input type="text" placeholder="请输入商品名"  class="sr-input" name="cname" />
					<button type="submit" class="btn sr-btn">
						<div>
							<img src="imgs/htimgs/sousuo.png" />
						</div>
					</button>
				</form>
			</div>
			<div class="inbox-body">
				<div class="mail-option">
					<div class="btn-group">
						<a class="btn-a selecttiaojian">
							请选择查询条件
							<img src="imgs/htimgs/selectxiala.png" />
						</a>
						<ul class="dropdown-menu dropdown1">
							<li id="zc">
								<a  href="htmain?v=splist&pageno=1">
									<img src="imgs/htimgs/spshangjia.png" />
									查询所有
								</a>
							</li>
							<li id="up">
								<a  href="htmain?v=uplist&pageno=1">
									<img src="imgs/htimgs/spshangjia.png" />
									上架商品
								</a>
							</li>
							<li id="down">
								<a href="htmain?v=downlist&pageno=1">
									<img src="imgs/htimgs/spxiajia.png" />
									下架商品
								</a>
							</li>
						</ul>
					</div>
					<div class="btn-group">
						<a class="btn-a" id="selectall">
							全选
						</a>
					</div>
					<div class="btn-group">
						<a class="btn-a piliang">
							批量操作
							<img src="imgs/htimgs/selectxiala.png" />
						</a>
						<ul class="dropdown-menu dropdown2" >
							<li id="upall">
								<a>
									<img src="imgs/htimgs/spshangjia.png" />
									上架
								</a>
							</li>
							<li id="downall">
								<a>
									<img src="imgs/htimgs/spxiajia.png" />
									下架
								</a>
							</li>
						</ul>
					</div>
					<div class="btn-group">
						<a target="frm" href="htmain?v=addcomm" class="btn-a">
							添加商品
						</a>
					</div>
					
					<ul class="unstyled pull-right">
						<li>
							<span>${commpager.pageNo}</span>
							<span>/</span>
							<span>${commpager.getPageCount()}</span>
						</li>
						<li>
							<a href="htmain?v=${method}&pageno=${commpager.getPrev()}&cname=${cname}" >
								<img src="imgs/htimgs/fyleft.png" >
							</a>
						</li>
						<li>
							<a href="htmain?v=${method}&pageno=${commpager.getNext()}&cname=${cname}">
								<img src="imgs/htimgs/fyright.png" >
							</a>
						</li>
					</ul>
				</div>
				<table class="list-table">
					<thead>
						<tr>
							<th></th>
							<th>商品图片</th>
							<th>商品名称</th>
							<th>分类</th>
							<th>品牌</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<c:forEach items="${commpager.data}" var="comm">
					<tr>
						<td>
							<input cid="${comm.cid}" type="checkbox" />
						</td>
						<td>
							<c:if var="c" test="${empty comm.cmain_img}">尚未添加</c:if>
							<c:if test="${not c}">
								<img src="${comm.cmain_img}" />
							</c:if>
						</td>
						<td>
						
							<a>${comm.cname}</a>
						</td>
						<td>
							<a>${comm.lname}</a>
						</td>
						<td>
							<a>${comm.bname }</a>
						</td>
						<td>
							<select cid="${comm.cid}" class="form-control selectisup">
								<option value="${comm.isup==0?'up':'down'}">${comm.isup==0?'上架':'下架'}</option>
								<option value="${comm.isup==0?'down':'up'}">${comm.isup==0?'下架':'上架'}</option>
							</select>
						</td>
						<td>
							<a target="frm" href="addcomm?v=updatecommpager&cid=${comm.cid}&cname=${comm.cname}">
								<img src="imgs/htimgs/spbianji.png" />
							</a>
							<a target="frm" href="htmain?v=guigecommlist&cid=${comm.cid}&cname=${comm.cname}">
								<img src="imgs/htimgs/fuspbtn.png" >
							</a>
						</td>
					</tr>
					</c:forEach>
				</table>
			</div>
		</div>
	</body>
</html>